package com.iflytek.autofly.setting.biz.base;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ScrollView;

import java.util.ArrayList;

/**
 * <b>Description: </b>TODO<br/>
 * <b>Change History:</b><br/>
 * <table border="1">
 * <tr>
 * <td><b>user</b></td>
 * <td><b>date</b></td>
 * <td><b>time</b></td>
 * <td><b>reason</b></td>
 * </tr>
 * <tr>
 * <td>JunLuan@iflytek.com</td>
 * <td>2015/11/27</td>
 * <td>13:50</td>
 * <td>创建此文件</td>
 * </tr>
 * </table>
 *
 * @author JunLuan@iflytek.com
 */
public class MyScrollView extends ScrollView {
    private ArrayList<View> mFreezeViewLists = new ArrayList<>();

    public MyScrollView(Context context) {
        super(context);
    }

    public MyScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void addFreezeView(View v) {
        mFreezeViewLists.add(v);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        float x = ev.getRawX();
        float y = ev.getRawY();
        for (View v : mFreezeViewLists) {
            if (v.isShown()) {
                int[] location = new int[2];
                v.getLocationOnScreen(location);
                if (x > location[0] && y > location[1] && x < location[0] + v.getWidth() && y < location[1] + v.getHeight()) {
                    return false;
                }
            }

        }
        return super.onInterceptTouchEvent(ev);
    }
}
